// pages/personnel/index/news/other/other.js
import {handPersonnelExchangeContact} from "../../../../../service/Message";
import {makePhoneCall, setClipboardData} from "../../../../../utils/Wx";
Component({

    /*
    * 默认接收全局样式
    * */
    options: {
        addGlobalClass: true
    },

    /**
     * 组件的属性列表
     */
    properties: {
        itemInfo: {
            type: Object,
            value: {}
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        agreeLoading: false,
        rejectLoading: false,
        _actionSheet: {
            show: false,
            list: [
                { name: "拨打", index: 0},
                { name: "复制", index: 1}
            ]
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        /*
        * 点击按钮
        * */
        bindClickBtn: async function (e) {
            let name = e.currentTarget.dataset.name;
            try {
                let id = this.data.itemInfo.id;
                let eventId = name === "agree" ? 1 : 2;
                let agreeLoading = this.data.agreeLoading;
                let rejectLoading = this.data.rejectLoading;
                if (agreeLoading || rejectLoading) return false
                this.setData({[name + "Loading"]: true});
                await handPersonnelExchangeContact({
                    id,
                    eventid: eventId
                })
                this.setData({"itemInfo.applyStatus": name === "agree" ? 1 : 2});
            } catch (e) {
                console.error(e)
            } finally {
                this.setData({[name + "Loading"]: false});
            }
        },
        
        /*
        * 点击联系方式
        * */
        bindShowSheet: function (e) {
            this.setData({"_actionSheet.show": true})
        },
        onSheetClose: function () {
            this.setData({"_actionSheet.show": false})
        },
        onSheetSelect: async function (e) {
            try {
                let index = e.detail.index;
                let itemInfo = this.data.itemInfo;
                let phone = itemInfo.message.phone;
                if (index === 0) { //拨打电话
                    await makePhoneCall(phone);
                } else if (index === 1) {
                    await setClipboardData(phone);
                }
            } catch (e) {
                console.error(e)
            }
        }
    }
})
